package main

import (
	"crypto/md5"
	"encoding/hex"
	"fmt"
	"sync"
	"time"
)

type Cat interface {
	CatchMouse()
}
type Dog interface {
	Bark()
}
type CatDog struct {
	Name string
}

func (catDog *CatDog) CatchMouse() {
	fmt.Printf("%v catch a mouse\n", catDog.Name)
}
func (catDog *CatDog) Bark() {
	fmt.Printf("%v bark\n", catDog.Name)
}
func main() {

	//catDog := &CatDog{"zs"}
	//
	//var cat Cat
	//cat = catDog
	//cat.CatchMouse()
	//
	//var dog Dog
	//dog = catDog
	//////dog.Bark()
	//typeOf := reflect.TypeOf(&CatDog{})
	strs := []string{"文若", "公达", "文和", "奉孝", "仲德", "公仁", "子扬"}
	results := work(strs)
	fmt.Println("结果是：", results)
}
func work(strs []string) sync.Map {
	//存放结果
	var result sync.Map
	var wg sync.WaitGroup
	wg.Add(len(strs))
	for i, str := range strs {
		go func(str string, i int) {
			start := time.Now().Unix()
			key := strs[i]
			temp := key
			time.Sleep(time.Second)
			fmt.Println("开始执行：", i, ":", key)
			s := ""
			for i := 0; i < 100000000; i++ {
				s = md5V(temp)
				temp = s
			}
			end := time.Now().Unix()
			fmt.Println(key, "对应的结果是：", temp, "耗时：", end-start)
			result.Store(key, temp)
			wg.Done()
		}(str, i)
		fmt.Println(str, "建立成功！")
	}
	fmt.Println("test")
	wg.Wait()
	return result
}
func md5V(str string) string {
	h := md5.New()
	h.Write([]byte(str))
	return hex.EncodeToString(h.Sum(nil))
}

/*
荀彧 文若
荀攸 公达
贾诩 文和
郭嘉 奉孝
程昱 仲德
董昭 公仁
刘晔 子扬
*/
